package jdk;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.ITurnSnapshot;
import robocode.control.testing.RobotTestBed;
import robocode.control.snapshot.IBulletSnapshot;

/**
 * This test checks whether bullet energy has reached '3'.
 * 
 * @author David Joel Lazaro - original
 * @author JD. Korse - derivative
 */
public class TestRasta01CalcuBulletEnergy extends RobotTestBed {
  ITurnSnapshot lastTurnSnapshot;
  boolean bulletEnergy = false;

  /**
   * Specifies that SittingDuck and Rasta01 be matched up for this test.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,jdk.Rasta01";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks to see if Rasta01 bullet energy is sufficient.
   * 
   * @param event Details about the completed turn.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    int energy = 0;
    lastTurnSnapshot = event.getTurnSnapshot();

    for (IBulletSnapshot damage : lastTurnSnapshot.getBullets()) {
      // Returns bullet energy
      energy = (int) damage.getPower();
    }

    if (energy >= 3) {
      bulletEnergy = true;
    }
  }
  

  /**
   * Asserts that Rasta01 used sufficient bullet energy.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Damage", bulletEnergy);
  }
}
